<?php

require_once 'Entity.php';

/**
 * Sieć restauracji.
 *
 * @author Rafał Cupał
 * @author Przemysław Furmańczyk
 */
class Chain extends Entity {
    protected $name = null;
    protected $owner = null;
    
    public function __construct($dataBase) {
        parent::__construct($dataBase, 'chains');
    }
    
    public function getName() {
        return $this->name;
    }
    
    public function setName($newName) {
        $this->name = $newName;
    }
    
    public function getOwner() {
        return $this->owner;
    }
    
    public function setOwner($newOwner) {
        $this->owner = (int)$newOwner;
    }
    
    public function load($rowData) {
        $this->id = $rowData['id'];
        $this->getRowData($rowData, $this->name, 'name');
        $this->getRowData($rowData, $this->owner, 'owner');
    }
    
    public function save() {
        $rowData = array();
        
        $this->setRowData($rowData, $this->name, 'name');
        $this->setRowData($rowData, $this->owner, 'owner');
        
        if ($this->id > 0) {
            $this->dataBase->update($this->tableName, $rowData, 
                    'id = ' . $this->id);
        }
        else {
            $this->dataBase->insert($this->tableName, $rowData);
            $this->id = $this->dataBase->lastInsertId();
        }
    }
}
